/* MenuApp.java 
* Created on Dec 21, 2012 
* Author:Mr.Viet
* Phone: 01683430426
* Email: phamvanvietcdhd@gmail.com
*/ 
package com.icode.utils; 

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import net.miginfocom.swing.MigLayout;

import com.icode.LAFApplet;
import com.session1.ConnectDBForm;

public class MenuApp extends JMenuBar implements ItemListener,ActionListener {
	private JMenu mFile, mEdit, mLaf;
	private JMenuItem mnOpen, mnSave;
	private JRadioButtonMenuItem mnLaf1, mnLaf2, mnLaf3, mnLaf4, mnLaf5,
			mnLaf6, mnLaf7, mnLaf8, mnLaf9, mnLaf10
			, mnLaf11, mnLaf12, mnLaf13, mnLaf14, mnLaf15, mnLaf16
			, mnLaf17, mnLaf18;
	private JMenuItem mnSession1;
	private JMenuItem mnEmployee;
	private LAFApplet mainApplet;
	public MenuApp(LAFApplet mainApplet ) {
		this.mainApplet = mainApplet;
		this.createMenu();
	}
	public void createMenu(){
		this.setLayout(new MigLayout());
		this.mFile = new JMenu("File");
		this.mEdit = new JMenu("Edit");
		this.mLaf = new JMenu("Look and feel");
		this.mnOpen = new JMenuItem("Open...");
		this.mnSave = new JMenuItem("Save as...");

		this.mnLaf1 = new JRadioButtonMenuItem("LegacyDefaul");
		this.mnLaf1
				.setName("org.jvnet.substance.SubstanceLegacyDefaultLookAndFeel");
		this.mnLaf2 = new JRadioButtonMenuItem("BusinessBlackSteel");
		this.mnLaf2
				.setName("org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel");
		this.mnLaf3 = new JRadioButtonMenuItem("Autumn");
		this.mnLaf3
				.setName("org.jvnet.substance.skin.SubstanceAutumnLookAndFeel");
		
		this.mnLaf6 = new JRadioButtonMenuItem("ChallengerDeep");
		this.mnLaf6
				.setName("org.jvnet.substance.skin.SubstanceChallengerDeepLookAndFeel");
		this.mnLaf7 = new JRadioButtonMenuItem("CremeCoffee");
		this.mnLaf7
				.setName("org.jvnet.substance.skin.SubstanceCremeCoffeeLookAndFeel");
		this.mnLaf8 = new JRadioButtonMenuItem("EmeraldDusk");
		this.mnLaf8
				.setName("org.jvnet.substance.skin.SubstanceEmeraldDuskLookAndFeel");
		this.mnLaf9 = new JRadioButtonMenuItem("Magma");
		this.mnLaf9
				.setName("org.jvnet.substance.skin.SubstanceMagmaLookAndFeel");
		this.mnLaf10 = new JRadioButtonMenuItem("MistAqua");
		this.mnLaf10.setName("org.jvnet.substance.skin.SubstanceMistAquaLookAndFeel");
		
		this.mnLaf11 = new JRadioButtonMenuItem("MistSilver");
		this.mnLaf11.setName("org.jvnet.substance.skin.SubstanceMistSilverLookAndFeel");
		this.mnLaf12 = new JRadioButtonMenuItem("Moderate");
		this.mnLaf12.setName("org.jvnet.substance.skin.SubstanceModerateLookAndFeel");
		this.mnLaf13 = new JRadioButtonMenuItem("NebulaBrickWall");
		this.mnLaf13.setName("org.jvnet.substance.skin.SubstanceNebulaBrickWallLookAndFeel");
		this.mnLaf14 = new JRadioButtonMenuItem("Nebula");
		this.mnLaf14.setName("org.jvnet.substance.skin.SubstanceNebulaLookAndFeel");
		this.mnLaf15 = new JRadioButtonMenuItem("OfficeBlue2007");
		this.mnLaf15.setName("org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel");
		this.mnLaf16 = new JRadioButtonMenuItem("RavenGraphiteGlass");
		this.mnLaf16.setName("org.jvnet.substance.skin.SubstanceRavenGraphiteGlassLookAndFeel");
		this.mnLaf17 = new JRadioButtonMenuItem("RavenGraphite");
		this.mnLaf17.setName("org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel");
		this.mnLaf18 = new JRadioButtonMenuItem("RavenLook");
		this.mnLaf18.setName("org.jvnet.substance.skin.SubstanceRavenLookAndFeel");
		
		this.mnSession1 = new JMenuItem("Connect DB");
		this.mnEmployee = new JMenuItem("Employee Management");
		this.mFile.add(this.mnSession1);
		
		ButtonGroup g = new ButtonGroup();
		g.add(this.mnLaf1);
		g.add(this.mnLaf2);
		g.add(this.mnLaf3);
		g.add(this.mnLaf6);
		g.add(this.mnLaf7);
		g.add(this.mnLaf8);
		g.add(this.mnLaf9);
		g.add(this.mnLaf10);
		g.add(this.mnLaf11);
		g.add(this.mnLaf12);
		g.add(this.mnLaf13);
		g.add(this.mnLaf14);
		g.add(this.mnLaf15);
		g.add(this.mnLaf16);
		g.add(this.mnLaf17);
		g.add(this.mnLaf18);

		this.mFile.add(this.mnOpen);
		this.mFile.add(this.mnSave);

		this.mLaf.add(this.mnLaf1);
		this.mLaf.add(this.mnLaf2);
		this.mLaf.add(this.mnLaf3);
		this.mLaf.add(this.mnLaf6);
		this.mLaf.add(this.mnLaf7);
		this.mLaf.add(this.mnLaf8);
		this.mLaf.add(this.mnLaf9);
		this.mLaf.add(this.mnLaf10);
		this.mLaf.add(this.mnLaf11);
		this.mLaf.add(this.mnLaf12);
		this.mLaf.add(this.mnLaf13);
		this.mLaf.add(this.mnLaf14);
		this.mLaf.add(this.mnLaf15);
		this.mLaf.add(this.mnLaf16);
		this.mLaf.add(this.mnLaf17);
		this.mLaf.add(this.mnLaf18);

		this.add(this.mFile);
		this.add(this.mEdit);
		this.add(this.mLaf);

		// Dang ky su kien
		this.mnLaf1.addItemListener(this);
		this.mnLaf2.addItemListener(this);
		this.mnLaf3.addItemListener(this);
		this.mnLaf6.addItemListener(this);
		this.mnLaf7.addItemListener(this);
		this.mnLaf8.addItemListener(this);
		this.mnLaf9.addItemListener(this);
		this.mnLaf10.addItemListener(this);
		this.mnLaf11.addItemListener(this);
		this.mnLaf12.addItemListener(this);
		this.mnLaf13.addItemListener(this);
		this.mnLaf14.addItemListener(this);
		this.mnLaf15.addItemListener(this);
		this.mnLaf16.addItemListener(this);
		this.mnLaf17.addItemListener(this);
		this.mnLaf18.addItemListener(this);
		
		this.mnSession1.addActionListener(this);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==this.mnSession1){
			ConnectDBForm f = new ConnectDBForm();
			f.parent = this.mainApplet;
			f.showForm();
		}
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		try {
			JRadioButtonMenuItem mn = (JRadioButtonMenuItem)e.getSource();
			UIManager.setLookAndFeel(mn.getName());
			SwingUtilities.updateComponentTreeUI(this.mainApplet);
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			e1.printStackTrace();
		} catch (UnsupportedLookAndFeelException e1) {
			e1.printStackTrace();
		}
	}

}
